package getDecimalValue;

public class Solution {
    public class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
    public int getDecimalValue(ListNode head) {
        // ans = ans*2+head.val
        int ans = 0;
        ListNode p = head;
        while (p!=null) {
            ans = ans*2 + p.val;
            p = p.next;
        }
        return ans;
    }
}
